/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package client;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.geom.GeneralPath;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Line2D;
import org.jbox2d.common.Color3f;
import org.jbox2d.common.Vec2;
import org.jbox2d.common.XForm;

/**
 * JMEDebugDraw for box2d. Unused at the moment.
 * [this class will be kept here because it may be useful later, although all
 * its methods implementations must change to draw stuff using jME]
 *
 * @author xissburg
 */
public class JMEDebugDraw extends org.jbox2d.dynamics.DebugDraw
{
    private Graphics2D g2D;
    private static final float Inv255 = 1.f/255.f;

    public JMEDebugDraw()
    {
        g2D = null;
    }

    public JMEDebugDraw(Graphics2D g2D)
    {
        this.g2D = g2D;
    }
    
    public void setGraphics(Graphics2D g2D){
        this.g2D = g2D;
    }
    
    @Override
    public void drawPolygon(Vec2[] vertices, int vertexCount, Color3f color) {
        GeneralPath gp = new GeneralPath();
        gp.moveTo(vertices[0].x, vertices[0].y);

        for(int i=0; i<vertices.length; ++i)
            gp.lineTo(vertices[i].x, vertices[i].y);

        g2D.setColor(new Color(color.x*Inv255, color.y*Inv255, color.z*Inv255));
        g2D.draw(gp);
    }

    @Override
    public void drawSolidPolygon(Vec2[] vertices, int vertexCount, Color3f color) {
        GeneralPath gp = new GeneralPath();
        gp.moveTo(vertices[0].x, vertices[0].y);

        for(int i=0; i<vertices.length; ++i)
            gp.lineTo(vertices[i].x, vertices[i].y);

        g2D.setColor(new Color(color.x*Inv255, color.y*Inv255, color.z*Inv255));
        g2D.fill(gp);
    }

    @Override
    public void drawCircle(Vec2 center, float radius, Color3f color) {
        g2D.setColor(new Color(color.x*Inv255, color.y*Inv255, color.z*Inv255));
        g2D.draw(new Ellipse2D.Float(center.x-radius, center.y-radius, radius*2, radius*2));
    }

    @Override
    public void drawSolidCircle(Vec2 center, float radius, Vec2 axis, Color3f color) {
        g2D.setColor(new Color(color.x*Inv255, color.y*Inv255, color.z*Inv255));
        g2D.fill(new Ellipse2D.Float(center.x-radius, center.y-radius, radius*2, radius*2));
    }

    @Override
    public void drawPoint(Vec2 position, float f, Color3f color) {
        g2D.setColor(new Color(color.x*Inv255, color.y*Inv255, color.z*Inv255));
        g2D.fillRect((int)(position.x+0.5f), (int)(position.y+0.5f), 1, 1);
    }

    @Override
    public void drawSegment(Vec2 p1, Vec2 p2, Color3f color) {
        g2D.setColor(new Color(color.x*Inv255, color.y*Inv255, color.z*Inv255));
        g2D.draw(new Line2D.Float(p1.x, p1.y, p2.x, p2.y));
    }

    @Override
    public void drawXForm(XForm xf) {
        //Uh?
    }

    @Override
    public void drawString(float x, float y, String s, Color3f color) {
        g2D.setColor(new Color(color.x*Inv255, color.y*Inv255, color.z*Inv255));
        g2D.drawString(s, x, y);
    }

}
